local shiliang = fk.CreateSkill{
    name = "SP_heg__shiliang",
}

Fk:loadTranslationTable{
    ["SP_heg__shiliang"] = "峙靓",
    [":SP_heg__shiliang"] = "当你每回合首次造成或受到伤害后，你可以摸一张牌，然后选择一项：1.令一名在你攻击范围外的其他势力角色摸一张牌；"..
    "2.你弃置一张牌。",
    ["#shiliangdrawcard-choose"] = "峙靓：选择一名在你攻击范围外的其他势力角色摸一张牌",
    ["#heg_shiliang-discard"] = "峙靓：你弃置一张牌",
    ["shiliang-drawcard"]= "令一名在你攻击范围外的其他势力角色摸一张牌",
    ["shiliang-discard"] = "弃置一张牌",
    ["#heg_shiliang-choose"] = "峙靓：选择一项",

    ["$SP_heg__shiliang1"] = "户犬闻寇至尚吠三两声，况我大魏义士乎？",
    ["$SP_heg__shiliang2"] = "观中原魏旗凋零，唯淮南独树义帜。",
}

local H = require "packages.ol_hegemony.util"

shiliang:addEffect(fk.Damaged,{
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(shiliang.name) and not player.dead and
      player:usedEffectTimes(self.name, Player.HistoryTurn) == 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:drawCards(player,1,shiliang.name)
        local choices = {"shiliang-discard"}
        if table.find(room.alive_players, function(p) return not player:inMyAttackRange(p) and not H.compareKingdomWith(p, player) end) then
          table.insert(choices, "shiliang-drawcard")
        end
        local choice = room:askToChoice(player, {
            choices = choices,
            skill_name = shiliang.name,
            prompt =  "#heg_shiliang-choose",
        })
        if choice == "shiliang-drawcard" then
          if player.dead then return end
          local targets = table.filter(room:getOtherPlayers(player, false), function(p) return not H.compareKingdomWith(p, player)
          and not player:inMyAttackRange(p) end)
          local tos = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#shiliangdrawcard-choose",
            skill_name = shiliang.name,
            cancelable = false,
          })
          if #tos > 0 then
            local to = tos[1]
            room:doIndicate(player.id, {to.id})
            room:drawCards(to, 1, shiliang.name)
          end
        else
          if not player:isKongcheng() then
          room:askToDiscard(player,{
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = shiliang.name,
            prompt = "#heg_shiliang-discard",
            cancelable = false,
          })
          end
        end
      end,
})

shiliang:addEffect(fk.Damage,{
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(shiliang.name) and not player.dead and
      player:usedEffectTimes(self.name, Player.HistoryTurn) == 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:drawCards(player,1,shiliang.name)
        local choices = {"shiliang-discard"}
        if table.find(room.alive_players, function(p) return not player:inMyAttackRange(p) and not H.compareKingdomWith(p, player) end) then
          table.insert(choices, "shiliang-drawcard")
        end
        local choice = room:askToChoice(player, {
            choices = choices,
            skill_name = shiliang.name,
            prompt =  "#heg_shiliang-choose",
        })
        if choice == "shiliang-drawcard" then
          if player.dead then return end
          local targets = table.filter(room:getOtherPlayers(player, false), function(p) return not H.compareKingdomWith(p, player)
          and not player:inMyAttackRange(p) end)
          local tos = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#shiliangdrawcard-choose",
            skill_name = shiliang.name,
            cancelable = false,
          })
          if #tos > 0 then
            local to = tos[1]
            room:doIndicate(player.id, {to.id})
            room:drawCards(to, 1, shiliang.name)
          end
        else
          if not player:isKongcheng() then
          room:askToDiscard(player,{
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = shiliang.name,
            prompt = "#heg_shiliang-discard",
            cancelable = false,
          })
          end
        end
      end,
})

return shiliang